package controller;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

public class InsertCloth_info {
    public static void main(String [] args){
        try {
            String str = "insert into clothes_info(number,size,cloth_id) values(?,?,?)";
            Connection connection = DBUtils.Connection();
            PreparedStatement preparedStatement = connection.prepareStatement(str);

            SAXReader saxReader = new SAXReader();
            Document read = saxReader.read("src/main/java/controller/cloth_info.xml");
            Element element = read.getRootElement();
            List<Element> list = element.elements();


            for (Element element1:list){
                String cloth_id = element1.element("cloth_id").getStringValue();
                String number = element1.element("number").getStringValue();
                String size = element1.element("size").getStringValue();
                preparedStatement.setString(3,cloth_id);
                preparedStatement.setString(1,number);
                preparedStatement.setString(2,size);
                preparedStatement.executeUpdate();



            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
